package com.gitee.wsl.transform.validator.annotation

import com.gitee.wsl.transform.validator.annotation.sample.DomainName
import com.gitee.wsl.transform.validator.annotation.sample.DomainNameValidator
import com.gitee.wsl.transform.validator.annotation.sample.Email
import com.gitee.wsl.transform.validator.annotation.sample.EmailValidator
import com.gitee.wsl.transform.validator.annotation.sample.IP
import com.gitee.wsl.transform.validator.annotation.sample.IPValidator
import com.gitee.wsl.transform.validator.annotation.sample.Length
import com.gitee.wsl.transform.validator.annotation.sample.LengthValidator
import com.gitee.wsl.transform.validator.annotation.sample.Max
import com.gitee.wsl.transform.validator.annotation.sample.MaxValidator
import com.gitee.wsl.transform.validator.annotation.sample.Min
import com.gitee.wsl.transform.validator.annotation.sample.MinValidator
import kotlin.reflect.KClass

val validatorsRegistry = hashMapOf<KClass<*>, Validator>(
    Email::class to EmailValidator(),
    IP::class to IPValidator(),
    DomainName::class to DomainNameValidator(),
    Min::class to MinValidator(),
    Max::class to MaxValidator(),
    Length::class to LengthValidator(),
)

inline fun <reified TClass : KClass<*>, TValidator : Validator> registerValidator(validator: TValidator) {
    validatorsRegistry[TClass::class] = validator
}